package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author 山顶洞人郑某
 * @className SetmealMapper.java
 * @date 2024 01 21
 */
@Mapper
public interface SetmealMapper {
    /**
     * 套餐分页查询
     * @param setmealPageQueryDTO
     * @return
     */
    Page<SetmealVO> page(SetmealPageQueryDTO setmealPageQueryDTO);

    @AutoFill(value = OperationType.INSERT)
   /* @Insert("insert into sky_take_out.setmeal (category_id, name, price, status, description, image, create_time," +
            " update_time, create_user, update_user) values (#{categoryId},#{name},#{price},#{status},#{description}," +
            "#{image},#{createTime},#{updateTime},#{createUser},#{updateUser})")*/
    void insert(Setmeal setmeal);

    @Select("select * from sky_take_out.setmeal where id = #{id}")
    Setmeal getById(Long id);

    /**
     * 修改套餐信息
     * @param setmeal
     */
    @AutoFill(value = OperationType.UPDATE)
    void update(Setmeal setmeal);

    /**
     * 商品起售和停售
     * @param status
     */
    @Update("update sky_take_out.setmeal set status = #{status} where id = #{id}")
    void status(Integer status,Long id);

    /**
     * 批量删除套餐信息
     * @param ids
     */
    void deleteByIds(List<Long> ids);

    @Select("select * from sky_take_out.setmeal where category_id = #{categoryId} and status = #{status} order by create_time desc")
    List<Setmeal> list(Long categoryId,Integer status);

    @Select("select count(id) from sky_take_out.setmeal where status = #{status}")
    Integer getSumByStatus(Integer status);
}
